// 组件添加到编辑区并选中
import { PublicConfigClass } from '@/components/publicConfig.js';

export function addEdit(item, e) {
	const data = cloneDeep(item);

	const newComponent = merge(new PublicConfigClass(data.orgConfig.events, data.orgConfig.config.data), data);

	if (e) {
		newComponent.orgConfig.attr.x = e.offsetX - newComponent.orgConfig.attr.w / 2;
		newComponent.orgConfig.attr.y = e.offsetY - newComponent.orgConfig.attr.h / 2;
	}
	// 添加
	$store.chart.addComponentList(newComponent, false, true);
	// 选中
	$store.chart.setTargetSelectChart(newComponent.id);
	console.log(newComponent);
	return newComponent;
}
